<?php 

$requestBody = file_get_contents("php://input");
if (empty($requestBody)) {
    die('send fail');
}
$content = json_decode($requestBody, true);

if ($content['ref'] == 'refs/heads/master' && $content['total_commits_count'] > 0 && $content['password'] == 'fwzi') {
    exec("cd D:\wamp64\gitee && git pull origin master 2<&1", $output, $return);
    $res_log = PHP_EOL . '----------------------------------------------------------------------------------------------------' . PHP_EOL;
    $res_log .= $content['user_name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '个commit：';
    $res_log .= PHP_EOL . "pull start --------" . PHP_EOL;
    $res_log .= '$output:' . var_export($output, true) . PHP_EOL . '$return:' . var_export($return, true) . PHP_EOL;
    $res_log .= PHP_EOL . "pull end --------" . PHP_EOL;
    //$res_log .= var_export($requestBody, true);

    file_put_contents("./git_webhook.log", $res_log, FILE_APPEND);//写入日志到log文件中
}